(function(){
	
globalObj.sdkCell = function sdkCellFn( id, candids, houses){
	var p = Object.create(sdkCell.proto);
	var o= {
		candids: candids,
		houses: houses,
		get id(){ return id}
	};
	p=Object.extend(p,o);
	return p;
};

globalObj.sdkCell.proto = {
		contains: function ( candid) {
			return this.candids.indexOf(candid)>=0;
		},
		isSolved: function (){ 
			return this.candids.length === 1;
		},
		enable: function( candidID, bool){
			if( bool && !this.contains( candidID)){
				this.candids.push( candidID);
				return this;
			}
			if( !bool && !this.contains( candidID)){
				return sdkChange("enable", this.id, candidID);
			}
		},
		disable: function( candidID, bool){
			if( bool && this.contains(candidID)){
				this.candids= this.candids.filter(function( elem){
					return elem !== candidID;
				});
				return this;
			}
			if( !bool && this.contains(candidID)){
				return sdkChange("disable", this.id, candidID);
			}
		},
		only: function( candidID, bool){
			if( bool){
				this.candids = ( this.candids.length === 1) ? rules.candidIDs: [candidID];
				return this;
			} else {
				return sdkChange("only", this.id, candidID);
			}
		},
		swap: function ( candidID, bool){	
			if( bool){
				if( this.contains( candidID)){
					this.disable( candidID, bool);
				}else{
					this.enable( candidID, bool);
				}
				return this;
			} else {
				return sdkChange("swap", this.id, candidID);
			}
		},
		isInHouse: function( houseId){
			return this.houses.indexOf( houseId ) >=0;
		},
		count: function(){
			return this.candids.length;
		}
};

globalObj.sdkCell.copy= function( cell){
	return sdkCell( cell.id, cell.candids.concat(), cell.houses.concat() );
};

})();

